package App.Repository;

import App.Model.Task.CrmTaskSchedule;

import java.math.BigInteger;
import java.sql.*;
import java.util.*;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 * Created by xw on 2019/1/7.
 */
public class ScheduleRepository {


    public Connection getConnection(String url, String username, String password) {
        try {
            return DriverManager.getConnection(url, username, password);
        } catch (SQLException ex) {
            return null;
            // throw ex;
        }
    }

    public List<CrmTaskSchedule> selectTaskSchedule(String url, String username, String password) throws Exception {

        List<CrmTaskSchedule> _scheduleList = new ArrayList<>();
        Connection conn = null;
        try {
            conn = getConnection(url, username, password);
            Statement stmt = conn.createStatement();
            String _strSql = " select recid, taskid,triggername,triggergroup,cronstring,begintime,reminderid " +
                    " from  crm_task_schedule where recstatus=1 limit 2  ";
            ResultSet rs = stmt.executeQuery(_strSql);

            ResultSetMetaData metadata = rs.getMetaData();
            while (rs.next()) {

                String _recid = rs.getString("recid");
                String _taskid = rs.getString("taskid");
                String _triggername = rs.getString("triggername");
                String _triggergroup = rs.getString("triggergroup");
                String _cronstring = rs.getString("cronstring");
                Date _begintime = rs.getDate("begintime");
                String _reminderid = rs.getString("reminderid");

                CrmTaskSchedule _schedule = new CrmTaskSchedule();
                _schedule.setRecid(_recid);
                _schedule.setTaskid(_taskid);
                _schedule.setTriggername(_triggername);
                _schedule.setTriggergroup(_triggergroup);
                _schedule.setCronstring(_cronstring);
                _schedule.setBegintime(_begintime);
                _schedule.setReminderid(_reminderid);
                _scheduleList.add(_schedule);

                System.out.println("_recid:" + _recid);
            }
            rs.close();
            conn.close();

        } catch (Exception ex) {
            ex.printStackTrace();
            throw ex;
        } finally {
            conn.close();
        }
        return _scheduleList;
    }







}
